﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Text;
using System.Drawing;
namespace DreamBox.BLL.User
{
    public class Avatar
    {
        public string Upload(HttpPostedFileBase imgFile,string UserID,string path)
        {
           

            bool state = true;
            //获取文件后缀
            string[] temp = imgFile.FileName.Split('.');
            string currentType = "." + temp[temp.Length - 1];
            string[] filetype = {".png", ".jpg", ".jpeg", ".bmp" };
            if (Array.IndexOf(filetype, currentType) == -1)
            {
                state = false;
            }
            //
            string localPath="/attached/" + System.Guid.NewGuid() + currentType;
            string newPath = "/attached/" + UserID + "/avatar/" + System.Guid.NewGuid() + currentType;
            if (state)
            {
                //获取缩略图对象
                //DreamBox.Net.Drawing.Picture pic = new DreamBox.Net.Drawing.Picture();
                //Image img = pic.Thumbnail(imgFile.InputStream, 120, 120);


                //img.Save(path + localPath);

                //img.Dispose();

                //DreamBox.Net.IO.IOStream ioStream = new DreamBox.Net.IO.IOStream();
                //Stream imgStream = ioStream.GetFile(path + localPath);
                //将图片流上传到又拍云
                Upyun.Upload upyun = new Upyun.Upload();
                upyun.ImgUpload(newPath, imgFile.InputStream);
                return "http://img.buyungu.com" + newPath + "!120g120";

            }
            else
            {
                return "";
            }
        }
    }
}
